import { Component } from "@angular/core";
import { AlertController } from "ionic-angular";
import { NavController, NavParams } from "ionic-angular";
import { DeatilRemarksPage } from "../detail-remarks/detail-remarks";
import { DebrisPage } from "../maince-type/debris/debris";
import { EmergencyrescuePage } from "../emergencyrescue/emergencyrescue";
import { RepairInfoPage } from "../repair-info/repair-info";
import { EmergencyEventListPage } from "../emergency-event-list/emergency-event-list";
import { DailyInspectionPage } from "../daily-inspection/daily-inspection";
import { EscalatorPage } from "../maince-type/escalator/escalator"; //自动扶梯 人行道
import { TractionPage } from "../maince-type/traction/traction";
import { HydpressPage } from "../maince-type/hydpress/hydpress";
import { Storage } from "@ionic/storage";
import * as moment from "moment";
import { RescuDrillPage } from "../rescue-drill/rescue-drill";
import { RepairListPage } from "../used-repair/repair-list/repair-list";
import { ApplyRepairPage } from "../repair-apply/apply-repair";
import { RepairApplyList } from "../repair-apply-list/repair-apply-list";
/**
 * 工作类型
 */
@Component({
  templateUrl: "worktype.html"
})
export class WorkTypePage {  //废弃不用了
  private isMaince: boolean = false;
  private isUsed: boolean = false;
  private ElevaType: string; //当前电梯类型 1 --工曳 2 --液压 3--杂物   4--自动扶梯
  private elevatorNum: string; //电梯编号
  private elevatorId: string; //电梯ID
  private isChose: number = 1; //登录人员类型选择
  private mainceType: string; //维保类型选取
  private testType: string; //检测类型
  private elevatorInfo: any; //电梯信息
  private mainceTypeList: any = [
    { label: "半月保", value: "1" },
    { label: "季度保", value: "2" },
    { label: "半年保", value: "3" },
    { label: "年保", value: "4" },
    { label: "维修", value: "5" },
    { label: "报修", value: "12" }
    // { label: '应急救援', value: '6' },
    // { label: '年度自检', value: '7' }
  ];
  private testTypeList: any = [
    // { label: '定期检查', value: '8' },
    { label: "巡检", value: "9" },
    { label: "维修", value: "11" },
    { label: "应急救援", value: "0" },
    { label: "救援演练", value: "10" },
    { label: "召修", value: "13" }
  ];
  constructor(
    public navCtrl: NavController,
    private alertCtrl: AlertController,
    private navParams: NavParams,
    private storage: Storage
  ) {
    this.ElevaType = navParams.get("elevatorType");
    this.elevatorNum = navParams.get("elevatorNum");
    this.elevatorInfo = navParams.get("elevatorInfo");
    this.elevatorId = navParams.get("elevatorId");
    storage.get("user").then(data => {
      this.isMaince =
        data.partyType == 1 &&
        data.roleId == 7 &&
        data.partyId == this.elevatorInfo.maintenancePartyId;
      this.isUsed =
        data.partyType == 2 &&
        data.roleId == 5 &&
        data.partyId == this.elevatorInfo.usedPartyId;
    });
  }
  doConfirm() {
    let type = "";
    let list = [];
    if (this.mainceType || this.testType) {
      type = this.mainceType == undefined ? this.testType : this.mainceType;
      list =
        this.mainceType == undefined ? this.testTypeList : this.mainceTypeList;
    } else {
      this.alertCtrl
        .create({
          title: "错误",
          message: "未选泽类型",
          buttons: ["确认"],
          enableBackdropDismiss: true
        })
        .present();
      return;
    }
    const alert = this.alertCtrl.create({
      title: "提示",
      message: "确认选择的工作类型为:" + this.codeValue(type, list),
      buttons: [
        {
          text: "取消",
          role: "cancel",
          handler: () => {
            console.log("Cancel clicked");
          }
        },
        {
          text: "确认",
          handler: () => {
            let data = new Date().getTime();
            switch (type) {
              case "1":
              case "2":
              case "3":
              case "4":
                // debugger;
                if (this.ElevaType == "1" || this.ElevaType == "5") {
                  //工曳电梯
                  this.navCtrl.push(TractionPage, {
                    ElevaType: this.ElevaType,
                    type: type,
                    elevatorNum: this.elevatorNum,
                    elevatorInfo: this.elevatorInfo,
                    data: data
                  }); //跳转 （月--年）保
                }
                if (this.ElevaType == "2") {
                  //液压
                  this.navCtrl.push(HydpressPage, {
                    ElevaType: this.ElevaType,
                    type: type,
                    elevatorNum: this.elevatorNum,
                    elevatorInfo: this.elevatorInfo,
                    data: data
                  }); //跳转 （月--年）保
                }
                if (this.ElevaType == "3") {
                  //杂物
                  this.navCtrl.push(DebrisPage, {
                    ElevaType: this.ElevaType,
                    type: type,
                    elevatorNum: this.elevatorNum,
                    elevatorInfo: this.elevatorInfo,
                    data: data
                  }); //跳转 （月--年）保
                }
                if (this.ElevaType == "4" || this.ElevaType == "6") {
                  //自动扶梯
                  this.navCtrl.push(EscalatorPage, {
                    ElevaType: this.ElevaType,
                    type: type,
                    elevatorNum: this.elevatorNum,
                    elevatorInfo: this.elevatorInfo,
                    data: data
                  }); //跳转 （月--年）保
                }
                break;
              case "5":
                // this.navCtrl.push(RepairInfoPage,this.navParams);//跳转维修
                this.navCtrl.push(RepairApplyList, this.navParams); //跳转维修列表
                break;
              case "6":
                this.navCtrl.push(EmergencyrescuePage, this.navParams); //跳转应急救援
                break;
              case "7":
                console.log("年度自保");
                break;
              case "8":
                console.log("定期检查");
                break;
              case "9":
                this.navCtrl.push(DailyInspectionPage, {
                  elevatorId: this.elevatorId,
                  data: new Date()
                }); //跳转巡检页面
                break;
              case "0":
                this.navCtrl.push(EmergencyEventListPage, {
                  elevatorId: this.elevatorId,
                  elevatorNum: this.elevatorNum
                }); //跳转应急救援
                break;
              case "10":
                this.navCtrl.push(RescuDrillPage); //救援演练
                break;
              case "11":
                this.navCtrl.push(RepairListPage); //维修（物业）
                break;
              case "12":
                this.navCtrl.push(ApplyRepairPage, {
                  applyType: "1",
                  elevatorId: this.elevatorId,
                  elevatorNum: this.elevatorNum
                }); //报修（维保）
                break;
              case "13":
                this.navCtrl.push(ApplyRepairPage, {
                  applyType: "2",
                  elevatorId: this.elevatorId,
                  elevatorNum: this.elevatorNum
                }); //招修（物业）
                break;
            }
          }
        }
      ]
    });
    alert.present();
  }
  /**
   * 码值 名称转换
   */
  codeValue(value: string, args: any[]) {
    if (args) {
      for (let i in args) {
        if (value == args[i].value) {
          return args[i].label;
        }
      }
    }
  }
}
